package com.happystreet.manager
{
	import com.happystreet.config.GameConfig;
	import com.happystreet.engine.CoreObject;
	import com.happystreet.engine.CoreShop;
	import com.happystreet.engine.MainUI;
	import com.happystreet.engine.StreetBackground;
	import com.happystreet.info.UserInfo;

	/**
	 *街道管理器 
	 * @author Liseen
	 * 
	 */	
	public class StreetManager extends CoreObject
	{
		public static var instance:StreetManager;
		public static var crowdLayer:CoreObject;
		public static var roadLayer:CoreObject;
		
		public function StreetManager()
		{
			super();
			instance = this;
			crowdLayer = new CoreObject();
			roadLayer = new CoreObject();
			
		}
		
		/**
		 *创建街道 
		 * @param userData
		 * 
		 */		
		public function buildStreet(userData:UserInfo):void
		{
			var shop:CoreShop;
			
			SleepManager.initSleepManager(this);
			anihilateStreet();
			
			if(MainUI.instance){
				MainUI.instance.showNavigationAndStatusBar();
			}
			
			
			userData.street = (userData.street!=null) ? userData.street :[];
			GameConfig.streetData = userData.street;
			//添加群众层
			this.add(crowdLayer);
			//添加道路层
			this.add(roadLayer);
			this.add(CollectionsManager.collectablesLayer);
			
			var all_rewards:Array = new Array();
			var i:int=0;
			while (i < userData.street.length)
			{
				shop = new CoreShop(i);
				GameConfig.addShop(shop);
				shop.alignTo((GameConfig.SHOP_AREA_WIDTH + GameConfig.SHOP_AREA_INTERVAL) * i, GameConfig.SHOP_AREA_GROUND);
				shop.buildShop();
				this.add(shop);
				this.setChildIndex(shop,0);
				i++;
			}
			
			//创建街道背景
			StreetBackground.instance.buildBackground(userData.background);
		}
		/**
		 *更换街道 
		 * 
		 */		
		public function changeStreet():void
		{
			
		}
		
		public function anihilateStreet():void
		{
			
		}
	}
}